package ${package}.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.github.pagehelper.PageHelper;
import ${package}.entity.EasyUiPageInfo;
import ${package}.entity.${classname};
import ${package}.mapper.${classname}Mapper;
import ${package}.util.CommUtil;
import com.jywl.util.ExcelUtil;
import ${package}.util.ResUtil;
import com.jywl.util.FileUtil;

@Controller
@RequestMapping("/${classnameL}")
public class ${classname}Controller {
	@Autowired
	private ${classname}Mapper ${classnameL}Mapper;	
	@RequestMapping("/list")
	public String userList(String error,Model model) {
		return "${classnameL}/${classnameL}";
	}
	
	@RequestMapping("/query")  
	@ResponseBody
	
    public EasyUiPageInfo<${classname}> queryUser(
    		@RequestParam("page") int page,
    		@RequestParam("rows") int rows,
    		@RequestParam HashMap<String, Object> params) {
	   PageHelper.startPage(page, rows);  
	   List<${classname}> ${classnameL}s = ${classnameL}Mapper.query(params);
	   return new EasyUiPageInfo<${classname}>(${classnameL}s);  
    } 
	
	@RequestMapping(value="/add",produces="application/json")  
	@ResponseBody	
    public HashMap<String, Object> add${classname}( @RequestBody List<${classname}> ${classnameL}s,HttpServletRequest request) {  
		HashMap<String, Object> res = ResUtil.getRes();
		for (${classname} ${classnameL} : ${classnameL}s) {
			if(null == ${classnameL}.get${pro}() || "".equals(${classnameL}.get${pro}())){
				${classnameL}.set${pro}(CommUtil.getUUID());
			}
		}
		${classnameL}Mapper.add(${classnameL}s);
       return res;  
    }
	@RequestMapping(value="/update",produces="application/json")  
	@ResponseBody	
    public HashMap<String, Object> edit${classname}( @RequestBody List<${classname}> ${classnameL}s,HttpServletRequest request) {  
		HashMap<String, Object> res = ResUtil.getRes();
		
		${classnameL}Mapper.update(${classnameL}s);
       return res;  
    }
	@RequestMapping(value="/delete",produces="application/json")  
	@ResponseBody	
    public HashMap<String, Object> delete${classname}( @RequestBody List<${classname}> ${classnameL}s,HttpServletRequest request) {  
		HashMap<String, Object> res = ResUtil.getRes();
		${classnameL}Mapper.delete(${classnameL}s);
       return res;  
    }
    @RequestMapping(value = "/exportByExcel") 
    public ModelAndView exportByExcel(@RequestParam HashMap<String, Object> params,HttpServletRequest request,  
            HttpServletResponse response) throws Exception {
		 
		PageHelper.startPage(0, 5000); 
		List<${classname}> ${classnameL}s = ${classnameL}Mapper.query(params);
		ExcelUtil.exportExcelByModel("${classnameL}.xlsx", ${classnameL}s, request, response, "${title}.xlsx");
        return null;  
    }
	
	/**获取Excel数据
	 * @param page
	 * @param rows
	 * @param params
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value = "/importByExcel")  
	@ResponseBody
	public Map<String, Object> importByExcel(
			  @RequestParam("excelFile") CommonsMultipartFile excelFile, HttpServletRequest request, HttpServletResponse response){ 
		List<${classname}> ${classnameL}s = null;
		HashMap<String, Object> res =  ResUtil.getRes();
		response.setContentType("application/json;charset=UTF-8"); 
		try {
			String path=FileUtil.upload(request);
			System.out.println(path);
			${classnameL}s= ExcelUtil.readExcelWithTitle(path, ${classname}.class);
			for (${classname} ${classnameL} : ${classnameL}s) {
			if(null == ${classnameL}.get${pro}()){
				${classnameL}.set${pro}(CommUtil.getUUID());
			}
			}
			${classnameL}Mapper.add(${classnameL}s);
		} catch (Exception e) {
			res.put("resCode","2");
			res.put("messege",e.getMessage());
			e.printStackTrace();
		}
	return res;
	} 
}


